package com.example.xihuashoujiduan.activity

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentPagerAdapter
import com.example.xihuashoujiduan.R
import com.example.xihuashoujiduan.base.BaseActivity
import com.example.xihuashoujiduan.databinding.ActivityTopicBinding
import com.example.xihuashoujiduan.fragment.DindanFragment
import com.example.xihuashoujiduan.fragment.HomeFragment
import com.example.xihuashoujiduan.fragment.WodeFragment
import com.example.xihuashoujiduan.viewmodel.Mainviewmodel
import com.google.android.material.tabs.TabLayout

class TopicActivity :BaseActivity<Mainviewmodel, ActivityTopicBinding>(R.layout.activity_topic){
    val listtiitle= mutableListOf<String>("首页","订单","我的")

    val fragmentlist= mutableListOf<Fragment>(HomeFragment(), DindanFragment(),WodeFragment())
    val tutu= mutableListOf<Int>(R.mipmap.one1,R.mipmap.two2,R.mipmap.three2)
    val tutu1= mutableListOf<Int>(R.mipmap.one1,R.mipmap.two1,R.mipmap.three1)
    val tutu2= mutableListOf<Int>(R.mipmap.one2,R.mipmap.two2,R.mipmap.three2)

    override fun initView() {

        binding.viewpage.adapter=object :FragmentPagerAdapter(supportFragmentManager){
            override fun getCount(): Int {
                return listtiitle.size
            }

            override fun getItem(position: Int): Fragment {
                return fragmentlist[position]
            }

            override fun getPageTitle(position: Int): CharSequence? {
                return listtiitle[position]
            }


        }

        binding.tabs.setupWithViewPager(binding.viewpage)

        binding.tabs.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
            override fun onTabSelected(tab: TabLayout.Tab) {
                tab.setIcon(tutu1[tab.position])



            }

            override fun onTabUnselected(tab: TabLayout.Tab) {

                tab.setIcon(tutu2[tab.position])
            }

            override fun onTabReselected(tab: TabLayout.Tab?) {

            }




        })







        for (i in 0  until tutu.size ){

            binding.tabs.getTabAt(i)?.setIcon(tutu[i])

        }



    }

    override fun dataObservese() {

    }
}